<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<scTable ref="table" :apiObj="apiObj"  :params="params" @selection-change="selectionChange" stripe remoteSort
					 remoteFilter>
				<el-table-column type="selection" width="50"></el-table-column>

				<el-table-column label="员工编码" prop="empNum" align="center" width="180"></el-table-column>
				<el-table-column label="姓名" prop="name" align="center" width="120"></el-table-column>
				<el-table-column label="性别" prop="sex" align="center" width="120"></el-table-column>
				<el-table-column label="在职状态" prop="status" align="center" width="120">
					<template #default="scope">
						<el-tag v-if="scope.row.status==0" type="danger">离职</el-tag>
						<el-tag v-if="scope.row.status==1" type="success">在职</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="岗位" prop="post" align="center" width="200"></el-table-column>
				<el-table-column label="部门" prop="dept" align="center" width="220"></el-table-column>
				<el-table-column label="操作" fixed="right" align="center" width="180">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row)">查看详情
							</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增用户',
					edit: '编辑用户',
					show: '查看'
				},
                apiObj: this.$API.emp.list,
                params: {},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					staffName:"",
					realName: "",
					staffEmail: "",
					staffPhone: "",
					staffSex: "",
					staffPass: "",
					orgId:"",
                    orgName: ""
					//group: []
				},
				//验证规则
				rules: {
					avatar:[
						{required: true, message: '请上传头像'}
					],
					userName: [
						{required: true, message: '请输入登录账号'}
					],
					name: [
						{required: true, message: '请输入真实姓名'}
					],
					password: [
						{required: true, message: '请输入登录密码'},
						{validator: (rule, value, callback) => {
							if (this.form.password2 !== '') {
								this.$refs.dialogForm.validateField('password2');
							}
							callback();
						}}
					],
					password2: [
						{required: true, message: '请再次输入密码'},
						{validator: (rule, value, callback) => {
							if (value !== this.form.password) {
								callback(new Error('两次输入密码不一致!'));
							}else{
								callback();
							}
						}}
					],
					dept: [
						{required: true, message: '请选择所属部门'}
					],
					group: [
						{required: true, message: '请选择所属角色', trigger: 'change'}
					]
				},
				//所需数据选项
				groups: [],
				groupsProps: {
					value: "id",
					emitPath: false,
					checkStrictly: true
				},
				depts: [],
				deptsProps: {
					value: "id",
					checkStrictly: true
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},

			submit(){

			},
			//表单注入数据
			setData(data){
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				this.form.orgId = data.id
				this.form.orgName = data.label
			}
		}
	}
</script>

<style>
</style>
